package com.alisveris.dao;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.lang3.StringUtils;

import java.io.*;

public class SepettenCikar extends HttpServlet {
	
   /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request,
	                 HttpServletResponse response)
	      throws IOException, ServletException
   {
      HttpSession session = request.getSession(false);
		
	  // kaldirilacak urunun index numarasinin tutulmasi
	  int urunNo = Integer.parseInt(request.getParameter("urun"));
		
	  AlisVerisSepeti sepet = (AlisVerisSepeti)
	  session.getAttribute("AlisVerisSepeti");
		      
	  if (sepet == null) {
	     sepet = new AlisVerisSepeti();
		 session.setAttribute("AlisVerisSepeti", sepet);
	  }
		
	  sepet.removeUrun(urunNo);
	  
	  String detayParameter = request.getParameter("detay");
	  String urunKod = request.getParameter("urunKod");
	  String product = request.getParameter("product");
	  
	  
	  if(!StringUtils.isEmpty(detayParameter) && detayParameter.equalsIgnoreCase("detay")){
		
		  response.sendRedirect(response
					.encodeRedirectURL("/e_ticaret/detay.jsp?urunKod="+urunKod+"&product="+product));	
		  
	  }else{
	  // urunun kaldirilmasi sonucu olusan sepetin gosterilmesi
      response.sendRedirect(response.encodeRedirectURL(
                      "/e_ticaret/anasayfa/index.jsp"));
      
	  }
   }
} 		      	                     